package com.controller.infocenter;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.IdentityInfo;
import com.po.PermissionInfo;
import com.po.ProfessionInfo;
import com.po.UserInfo;
import com.service.infocenter.IdentityService;
import com.service.infocenter.ProfessionService;
import com.service.infocenter.UserService;

@Controller
@RequestMapping("/jsp/infocenter")
public class UserController {
	@Resource(name = "userServiceImp")
	private UserService userService;
	@Resource(name = "professionServiceImp")
	private ProfessionService professionService;
	@Resource(name = "identityServiceImp")
	private IdentityService identityService;
	
	@ResponseBody
	@RequestMapping(value = "/getUserList")
	public List<UserInfo> getUserList(String user_id) {
		UserInfo user=new UserInfo();
		user.setUser_id(user_id);
		List<UserInfo> list=userService.getUserList(user);
		return list;
	}
	//进入用户个人中心页面
	@RequestMapping(value = "/getUser")
	public String getUser(Model model,HttpServletRequest request,HttpServletResponse resp)throws IOException {		
		UserInfo userinfo=userService.getUser(request.getSession().getAttribute("user_id").toString());
		String rolename = (String) request.getSession().getAttribute("role_name");
		model.addAttribute("user", userinfo);
		List<IdentityInfo> identitylist=identityService.getIdentityList();
		model.addAttribute("identity", identitylist);	
		List<ProfessionInfo> professionlist=professionService.getProfessionList();
		model.addAttribute("profession", professionlist);
		model.addAttribute("rolename", rolename);
		return "infocenter/infopersonal";
	}
	@ResponseBody
	@RequestMapping(value = "/getIdentityList")
	public List<IdentityInfo> getIdentityList() {
		List<IdentityInfo> list=identityService.getIdentityList();
		return list;
	}
	@ResponseBody
	@RequestMapping(value = "/getProfessionList")
	public List<ProfessionInfo> getProfessionList() {
		List<ProfessionInfo> list=professionService.getProfessionList();
		return list;
	}
	@ResponseBody
	@RequestMapping(value = "/updateUser")
	public int updateUser(UserInfo userinfo) {
		int i=userService.updateUser(userinfo);
		return i;
	}
	
	@RequestMapping(value="/getinfocenter")
	public String getinfocenter(Model model,HttpServletRequest request){	
		String userid = request.getSession().getAttribute("user_id").toString();
		List<PermissionInfo> permissionlist = userService.getUserPermission(userid);
		model.addAttribute("permissionlist",permissionlist);
		return "infocenter/infocenter";
	}
	
}
